//  CG2 ueb_3.1
// S.Shanmugaesan  (1061630)  Michael Antemann (10616753)
#include <GL/gl.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

int xx=0,yy=0,zz=0;
double strichBreite=10.0;
double koerper_1=100.0;
double koerper_2=20.0;
double koerper_3=180.0;
double koerper_4=20.0;
double koerper_5=10.0;
double koerper_6=110.0;

void init(void)
{
	glClearColor (0.0, 0.0, 0.0, 0.0);
	glShadeModel (GL_FLAT);
}

void display(void)
{
	glClear (GL_COLOR_BUFFER_BIT);
	//Linienstaerke
	glLineWidth(3.0);
	//CUBE
	glPushMatrix();
	glTranslatef(0.0,0.0,-650.0);

	glColor3f(1.0,1.0,1.0);
	glRotatef((GLfloat)xx,1.0,0.0,0.0);
	glRotatef((GLfloat)yy,0.0,1.0,0.0);
	glRotatef((GLfloat)zz,0.0,0.0,1.0);
	glutWireCube(300);

	glTranslatef(-100.0,-25.0,0.0);

		glBegin(GL_LINES);
		glColor3f (0.0, 1.0, 0.0);
		glVertex3f(0.0,0.0,0.0);
		glVertex3f(0.0,koerper_1,0.0); // y=100
		glEnd();
		//strich
		glBegin(GL_LINES);
		glLineWidth(3.5);
		glColor3f (1.0, 0.0, 0.0);

		glVertex3f(-strichBreite,0.0,0.0);
		glVertex3f(strichBreite,0.0,0.0);
		glEnd();

		glTranslatef(0.0,100.0,0.0);

		glBegin(GL_LINES);
		glColor3f (0.0, 0.5, 1.0);
		glVertex3f(0.0,0.0,0.0);
		glVertex3f(0.0,koerper_2,0.0); // y=20
		glEnd();
		//Strich
		glBegin(GL_LINES);
		glColor3f (1.0, 0.0, 0.0);

		glVertex3f(-strichBreite,0.0,0.0);
		glVertex3f(strichBreite,0.0,0.0);
		glEnd();

		glTranslatef(0.0,20.0,0.0);

		glBegin(GL_LINES);
		glColor3f (0.0, 0.0, 1.0);
		glVertex3f(0.0,0.0,0.0);
		glVertex3f(koerper_3,-10.0,20.0); // x=180
		glEnd();
		//Strich
		glBegin(GL_LINES);
		glColor3f (1.0, 0.0, 0.0);

		glVertex3f(0.0,0.0,-strichBreite);
		glVertex3f(0.0,0.0,strichBreite);
		glEnd();

		glTranslatef(koerper_3,-10.0,20.0);

		glBegin(GL_LINES);
		glColor3f (1.0, 0.5, 0.5);
		glVertex3f(0.0,0.0,0.0);
		glVertex3f(koerper_4,-2.0,3.0); // x=180
		glEnd();
		//Strich
		glBegin(GL_LINES);
		glColor3f (1.0, 0.0, 0.0);

		glVertex3f(0.0,0.0,-strichBreite);
		glVertex3f(0.0,0.0,strichBreite);
		glEnd();

		glTranslatef(koerper_4,-2.0,3.0); //

		glBegin(GL_LINES);
		glColor3f (0.5, 0.5, 1.0);
		glVertex3f(0.0,0.0,0.0);
		glVertex3f(koerper_5,-20.0,10.0); // x=10
		glEnd();
		//Strich
		glBegin(GL_LINES);
		glColor3f (1.0, 0.0, 0.0);

		glVertex3f(0.0,0.0,-strichBreite);
		glVertex3f(0.0,0.0,strichBreite);
		glEnd();

		glTranslatef(koerper_5,-20.0,10.0);

		glBegin(GL_LINES);
		glColor3f (0.1, 0.5, 0.5);
		glVertex3f(0.0,0.0,0.0);
		glVertex3f(30,-80.0,35.0); // x=
		glEnd();
		//Strich
		glBegin(GL_LINES);
		glColor3f (1.0, 0.0, 0.0);

		glVertex3f(0.0,0.0,-strichBreite);
		glVertex3f(0.0,0.0,strichBreite);
		glEnd();

		glTranslatef(30,-80.0,35.0); //
		glBegin(GL_LINES);
		glColor3f (1.0, 0.0, 0.0);

		glVertex3f(0.0,0.0,-strichBreite);
		glVertex3f(0.0,0.0,strichBreite);
		glEnd();


		glPopMatrix();
	glutSwapBuffers();// setVisible
}

void keyboard(unsigned char key, int x, int y) {
	switch (key) {

	case 'x':
			xx = (xx + 5) % 360;
				glutPostRedisplay();
				break;
	case 'y':
			yy = (yy + 5) % 360;
				glutPostRedisplay();
				break;
	case 'z':
			zz = (zz + 5) % 360;
				glutPostRedisplay();
				break;

	case 'X':
			xx = (xx - 5) % 360;
				glutPostRedisplay();
				break;
	case 'Y':
			yy = (yy - 5) % 360;
				glutPostRedisplay();
				break;
	case 'Z':
			zz = (zz - 5) % 360;
				glutPostRedisplay();
				break;

	glutPostRedisplay();
	break;

	case 27:
		exit(0);
		break;
	default:
		break;
	}
}

void reshape(int w, int h)
{
	glViewport (0, 0, (GLsizei) w, (GLsizei) h);
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	//glOrtho(-12.0,12.0,-12.0,12.0,0.0,12.0);
	//glOrtho(-400.0, 400.0, -400.0, 400.0, -400.0, 400.0);
    gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,-5,5);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize (800, 800);
	glutInitWindowPosition (50, 50);
	glutCreateWindow (argv[0]);
	init ();
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);

	glutMainLoop();
	return 0;
}
